/*    */ package cn.zzuisa.news.servlet;
/*    */ 
/*    */ import java.io.IOException;
/*    */ import java.util.concurrent.CopyOnWriteArraySet;
/*    */ import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.websocket.OnClose;
/*    */ import javax.websocket.OnMessage;
/*    */ import javax.websocket.OnOpen;
/*    */ import javax.websocket.Session;
/*    */ 
/*    */ 
/*    */ @WebServlet(name = "socket", urlPatterns = {"/socket"}, asyncSupported = true)
/*    */ public class WebSocket
/*    */   extends HttpServlet
/*    */ {
/*    */   private Session session;
/* 20 */   private static CopyOnWriteArraySet<WebSocket> webSockets = new CopyOnWriteArraySet();
/*    */   @OnOpen
/*    */   public void onOpen(Session session) {
/* 23 */     this.session = session;
/* 24 */     webSockets.add(this);
/*    */   }
/*    */   
/*    */   @OnClose
/* 28 */   public void onClose() { webSockets.remove(this); }
/*    */ 
/*    */   
/*    */   @OnMessage
/*    */   public void onMessage(String message) {}
/*    */ 
/*    */   
/*    */   public void sendMessage(String message) {
/* 36 */     for (WebSocket webSocket : webSockets) {
/*    */       try {
/* 38 */         webSocket.session.getBasicRemote().sendText(message);
/* 39 */       } catch (IOException e) {
/* 40 */         e.printStackTrace();
/*    */       } 
/*    */     } 
/*    */   }
/*    */ 
/*    */ 
/*    */   
///* 47 */   protected StreamInbound createWebSocketInbound(String arg0, HttpServletRequest arg1) { return null; }
/*    */ }


/* Location:              /Users/frank/Desktop/admin/WEB-INF/classes/!/cn/zzuisa/news/servlet/WebSocket.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.0.7
 */